package com.lsyw.intergrate.common.MybatisPlus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动填充功能
 *
 * @author alicas
 * @date 2020-09-01
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		//log.info("start insert fill ....");
		this.strictInsertFill(metaObject, "gmtCreate", Date.class, new Date());

		this.strictInsertFill(metaObject, "status", Integer.class, 1);
		this.strictInsertFill(metaObject, "delFlag", Integer.class, 0);
		try {
			this.strictInsertFill(metaObject, "gmtCreateUser", Long.class, Long.parseLong("1503924399299358722"));
		} catch (Exception e) {
			// 捕获定时任务记录日志时无法获取用户上下文信息的异常
		}
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		//log.info("start update fill ....");
		this.strictUpdateFill(metaObject, "gmtModified", Date.class, new Date());
		try {
			this.strictUpdateFill(metaObject, "gmtModifiedUser", Long.class, Long.parseLong("1503924399299358722"));
		} catch (Exception e) {
			// 捕获定时任务记录日志时无法获取用户上下文信息的异常
		}
	}

}
